<?php 
	class Db_room extends CI_Model{
		public function __construct(){
			parent::__construct();
		}
		
		public function room_cat_all(){
			$config['base_url'] = base_url().'manage_room/room_cat_list';
			$config['total_rows'] = $this->db->count_all("hotel_room_type");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("pkid", "desc");
			$res = $this->db->get('hotel_room_type');
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$cat = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['name_en']				=$P['type_en'];
				$cat[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($cat,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function room_all(){
			$config['base_url'] = base_url().'manage_room/room_list';
			$config['total_rows'] = $this->db->count_all("hotel_room");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->select('t2.pkid,t2.room_no,t1.type_en as cat_name');
			$this->db->from('hotel_room_type t1');
			$this->db->join('hotel_room t2', 't1.pkid = t2.hotel_type_pkid');
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("t2.pkid", "desc");
			$res = $this->db->get();
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$item = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['title_en']					=$P['room_no'];
				$tmp['name_en']				=$P['cat_name'];
				$item[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($item,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function show_cat($group = ""){
			$this->db->order_by("pkid","desc");
			$res = $this->db->get('hotel_room_type');
			$str = '<option value="">=select category=</option>';
			foreach ($res->result_array() as $P){
				if($group == $P['pkid']){
					$check = 'selected="selected"';
				}else{
					$check = "";
				}
				$str .='<option value="'.$P['pkid'].'" '.$check.'>'.$P['type_en'].'</option>';
			}
			return $str;
		}
		
		public function front_room_cat_all(){
			$config['base_url'] = base_url().'manage_room/front_room_cate';
			$config['total_rows'] = $this->db->count_all("hotel_info_front_category");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("pkid", "desc");
			$res = $this->db->get('hotel_info_front_category');
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$cat = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['name_en']				=$P['name_en'];
				$cat[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($cat,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function front_room_subcat_all(){
			$config['base_url'] = base_url().'manage_room/front_room_subcate';
			$config['total_rows'] = $this->db->count_all("hotel_info_front_subcategory");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->select('t1.pkid,t1.name_en,t2.name_en as pname');
			$this->db->from("hotel_info_front_subcategory t1");
			$this->db->join("hotel_info_front_category t2", 't1.category_pkid=t2.pkid');
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("t1.pkid", "desc");
			$res = $this->db->get();
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$cat = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['name_en']				=$P['name_en'];
				$tmp['pname']					=$P['pname'];
				$cat[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($cat,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function room_cat($group = ""){
			$this->db->order_by("pkid","desc");
			$res = $this->db->get('hotel_info_front_category');
			$str = '<option value="">=select category=</option>';
			foreach ($res->result_array() as $P){
				if($group == $P['pkid']){
					$check = 'selected="selected"';
				}else{
					$check = "";
				}
				$str .='<option value="'.$P['pkid'].'" '.$check.'>'.$P['name_en'].'</option>';
			}
			return $str;
		}
		
		public function room_subcat($group = ""){
			$this->db->order_by("pkid","desc");
			$res = $this->db->get('hotel_info_front_subcategory');
			$str = '<option value="">=select sub category=</option>';
			foreach ($res->result_array() as $P){
				if($group == $P['pkid']){
					$check = 'selected="selected"';
				}else{
					$check = "";
				}
				$str .='<option value="'.$P['pkid'].'" '.$check.'>'.$P['name_en'].'</option>';
			}
			return $str;
		}
		
		public function front_room_listall(){
			$config['base_url'] = base_url().'manage_room/front_room_list';
			$config['total_rows'] = $this->db->count_all("hotel_info_front");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->select('t1.pkid,t1.name_en,t1.img,t2.name_en as pname,t3.name_en as sname');
			$this->db->from("hotel_info_front t1");
			$this->db->join("hotel_info_front_category t2", 't1.category_pkid=t2.pkid','left');
			$this->db->join("hotel_info_front_subcategory t3", 't1.subcategory_pkid=t3.pkid','left');
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("t1.pkid", "desc");
			$res = $this->db->get();
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$cat = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['name_en']				=$P['name_en'];
				$tmp['pname']					=$P['pname'];
				$tmp['sname']					=$P['sname'];
				$cat[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($cat,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function dropdownlist(){
			$str ='
				<script type="text/javascript" language="javascript">
					    function getCity(strURL)
					    {         
					     var req = getXMLHTTP(); // fuction to get xmlhttp object
					     if (req)
					     {
					      req.onreadystatechange = function()
					     {
					      if (req.readyState == 4) { //data is retrieved from server
					       if (req.status == 200) { // which reprents ok status                    
					         document.getElementById(\'citydiv\').innerHTML=req.responseText;
					      }
					      else
					      { 
					         alert("There was a problem while using XMLHTTP:\n");
					      }
					      }            
					      }        
					    req.open("POST", strURL, true); //open url using get method
					    req.send(null);
					     }
					    }
			</script>
			';
			return $str;
		}
		
	}
?>